<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file administrator.php */
/* Location: ./auth/controllers/administrator.php */
class Administrator extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->model('auths'); /* Load Model from auth/models/auths*/
   }
   
	public function index(){
		$val = array('title'=>lang('auth'));
		$this->load->view('administrator/auth',$val); /* view template in view administrator*/
	}
	
	function do_login(){
	    /* check if username and password empty*/   
		if(($this->input->post('username')== "") && ($this->input->post('password') == "")):
			$message = "Fill up Username and  Password";
			$bg_color = "#FFEBE8";
			$status   = "failed";
			$redirect = '';
		/* check if username not empty and password empty*/
        elseif(($this->input->post('username')!= "") && ($this->input->post('password') == "")):
			$message = "Fill up Password";
			$bg_color = "#FFEBE8";
			$status   = "failed";
			$redirect = '';
        /* check if username empty and password not empty*/
		elseif(($this->input->post('username')== "") && ($this->input->post('password') != "")):
			$message = "Fill up Password";
			$bg_color = "#FFEBE8";
			$status   = "failed";
			$redirect = '';	
		/* check if username not empty and password  not empty*/
        elseif (($this->input->post('username') != "") || ($this->input->post('password') != "")):
			/* Cek Email And Password if verified */
			if($this->auths->getVerifiedMember($this->input->post('username'),$this->input->post('password'))>0):
				$message = "Username and password matched.";
				$bg_color = "#FFA";
				$status   = "success";
				$redirect = site_url('dashboard/administrator');
			/* Cek Email And Password if NOT verified */
            else:
				$message  = "Username or password do not match.";
				$bg_color = "#FFEBE8";
				$status   = "failed";
				$redirect = '';
			endif;
			/* Cek Email And Password */
		endif;
        /*JSON output*/
		$output = '{"message": "'.$message.'","status": "'.$status.'","redirect": "'.$redirect.'","bg_color": "'.$bg_color.'"}';
		echo $output;
	}
    
    /* function log out*/
    function do_logout(){
        $this->session->sess_destroy();
		redirect('administrator',301);
    }
}
/* End of file administrator.php */
/* Location: ./auth/controllers/administrator.php */